<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2019-04-25
 * Time: 22:04
 */

namespace App\Helper;


use App\Exceptions\OperateFailedException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

trait SendRequest
{
    public function sendRequst($method, $uri, $param = null){
        try{
            $client = new Client();
            $param ? $res = $client->request($method, $uri, $param) : $res = $client->request($method, $uri);
        }catch (ClientException $exception) {
            throw new OperateFailedException('Failed to request');
        }
        return json_decode($res->getBody()->getContents());
    }
}